package com.starlink.common;

import org.springframework.stereotype.Component;

import java.util.concurrent.ConcurrentHashMap;

/**
 * 锁
 */
@Component
public class EntranceLock {
    private final ConcurrentHashMap<String, Object> entranceMap = new ConcurrentHashMap<>();

    public boolean tryLock(String idCard) {
        return entranceMap.putIfAbsent(idCard, new Object()) == null;
    }

    public void unlock(String idCard) {
        entranceMap.remove(idCard);
    }
}
